var a,adr,auth,Delay=300,GM
var mp,dis=[1,1,1,1,1,1,1,1,1,1],b,i,j
var Rel_chg_a,IO_chg_a,Log_chg_a
var bg="background-color:"
var tb="<table cellspacing=7 border=0 style='background:#898989;color:#FFF;width:580px'><tr height=30>"
var bg_e="#080'>"
var bg_a="#624F4F'>"
var bg_ee="#958787;border:1px inset #ccc'>"
var bg_ea="#75997B;border:1px inset #ccc'>"

function B(b){return Boolean(Number(b))}

function tm(){
try{
xhttp=new XMLHttpRequest()
xhttp.open("GET","daten.cfg",false)
xhttp.send("")
var p = xhttp.responseText.split(";") 

if(p[11]=='end'){
parent.Name=p[0]
parent.a_time=p[1]
parent.Rel_chg=p[2]
parent.IO_chg=p[3]
parent.Log_chg=p[4]
parent.ClockStat=p[5]
parent.Login=p[6]
parent.Ver=p[7]
parent.BootTime=parseInt(p[8])+parseInt(p[9])*65536
parent.Typ=p[10]
}}catch(e){}}

function s(t,adr,auth){
xhttp=new XMLHttpRequest()
xhttp.open("POST",adr+"ctrl.htm"+auth,false)
xhttp.setRequestHeader("Content-type","text/plain")
if(t=='h') xhttp.send('h=0'); else xhttp.send(t)}

function rel_r(adr,auth){
try{xhttpe=new XMLHttpRequest()
xhttpe.open("GET",adr+"strg.cfg"+auth,false)
try{xhttpe.timeout = 3000} catch(e){}
xhttpe.send("")
a = xhttpe.responseText.split(";")
} catch(e){return false}
return true}

function io_r(adr,auth){
try{xhttpe=new XMLHttpRequest()
xhttpe.open("GET",adr+"ioa.cfg"+auth,false)
xhttpe.send("")
a = xhttpe.responseText.split(";")
} catch(e){return false}
return true}

function r_read(adr,auth){
var b,i
rel_r(adr,auth)
if(a[58]=='end'){
b=tb
for(i=0;i<8;i++){
if(a[30+i]==1){b+="<td id=btn title='gesperrt' style='";if(a[20+i]==1) b+=bg+bg_ea; else b+=bg+bg_ee}
else {
b+="<td id=bt title='"+a[40+i]+"\n"
if(a[50+i].match('T') && a[50+i].match('K'))b+='Timer & Keepalive eingeschltet'; else if(a[50+i].match('T'))b+='Timer eingeschltet'; else if(a[50+i].match('K'))b+='Keepalive eingeschltet'
if(a[30+i]==0) b+="' onClick=\"this.style.border='2px inset #ddd'; this.style['box-shadow']='#ddd 0 0 0px'; Rel_chg_a++;s('F"+i+"=S','"+adr+"','"+auth+"');del_rel()\""; else b+="'"
b+=" style='"
if(a[20+i]==1) b+=bg+bg_e; else b+=bg+bg_a
}
b+=a[10+i]
if(i==3)b+="<tr height=30>"
}
b+="</table>" 
document.getElementById('rel_z').innerHTML=b
}}

function io_read(adr,auth){
var b,i
a=""
io_r(adr,auth)
if(a.length==1){
try{	
document.getElementById('io1').style.visibility="collapse"
document.getElementById('io2').style.visibility="collapse"
}catch(e){}
return}
if(a[33]=='end'){
b=tb
for(i=0;i<8;i++)
{
var s=B(a[i*4+2]),ea=B(a[i*4+3]),inv=B(a[i*4+4])

b+="<td title='"
if(!ea){
b+="Ausgang"
if(inv){b+="\nInventiert";s=!s}
b+="' onClick=\"this.style.border='2px inset #ddd';this.style['box-shadow']='#ddd 0 0 0px'; IO_chg_a++;s('E"+i+"=S','"+adr+"','"+auth+"');del_io()\""
b+=" id=bt style='"
if(s) b+=bg+bg_e; else b+=bg+bg_a}
else {
b+="Eingang - kein Schalten"
if(inv){b+="\nInventiert";s=!s}
b+="' id=bte style='"
if(s) b+=bg+bg_ee; else b+=bg+bg_ea
}
b+=a[i*4+1] 
if(i==3)b+="<tr height=30>"
}
b+="</table>" 
document.getElementById('io_z').innerHTML=b
}}

function del_rel(){Rel_chg_a++;window.setTimeout("r_read('','')",Delay)}
function del_io(){IO_chg_a++;window.setTimeout("io_read('','')",Delay)}
function ref(){rel_ch();io_ch();window.setTimeout('ref()',500)}
function rel_ch(){if(parent.Rel_chg!=Rel_chg_a){Rel_chg_a=parent.Rel_chg;r_read('','')}}
function io_ch(){if(parent.IO_chg!=IO_chg_a){IO_chg_a=parent.IO_chg;io_read('','')}}

function p_read(){
g="<a href='sv.htm'>"+a[59]+"</a> &nbsp;&nbsp;&nbsp; "+a[7]+"&deg;C &nbsp;&nbsp;&nbsp;<a href=netcfg.htm><span style='color:#AAAAAA'> IP: "+a[2]
if(a[6]!='80')g+=":"+a[6]
g+="</span></a>"
document.getElementById('h').innerHTML=g}